<template>
	<view class="content">
		<view class="title" style="font-size: 50rpx; margin-bottom: 20rpx; font-weight: bold;">子组件B</view>
		<view class="b-box">
			<text>CompA组件传进来的值：</text>
			<!-- 示例中是蓝色背景+白色文字 -->
			<text class="intent-text-box">{{result}}</text>
		</view>
		<view class="b-box" style="margin: 10rpx 0;">
			<text style="font-size: 32rpx;">回传值：</text>
			<input type="text" v-model="callbackValue" style="color: yellowgreen; border: 1px solid #ccc; padding: 10rpx; margin: 0 20rpx; flex: 1;" />
			<button @click="sendOutside()" class="back-btn">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				result: '',
				callbackValue: '0595-2788888'
			};
		},
		created() {
			uni.$on('getIntent', (msg) => {
				console.error("-----CompB----getIntent----->" + msg);
				this.result = msg;
			});
		},
		methods: {
			sendOutside() {
				console.log("----CompB----sendOutside------>" + this.callbackValue);
				this.$emit('callBackFun', this.callbackValue);
			}
		},
		beforeUnmount() {
			uni.$off('getIntent');
		}
	}
</script>

<style>
	/* 子组件B背景：绿色 */
	.content {
		background-color: #ccffff;
		padding: 30rpx;
	}
	.b-box {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		margin: 20rpx 0;
		font-size: 32rpx;
	}
	/* CompA传过来的值：蓝色背景+白色文字 */
	.intent-text-box {
		background-color: #1677ff; /* 蓝色背景 */
		color: #fff; /* 白色文字 */
		padding: 5rpx 15rpx;
		border-radius: 5rpx;
	}
	/* 回传按钮样式：浅灰色背景 */
	.back-btn {
		background-color: #f5f5f5; /* 浅灰色 */
		color: #000;
		font-size: 32rpx;
		padding: 10rpx 20rpx;
	}
</style>